/**
 * Created by Administrator on 2018/1/31 0031.
 */

storePic = function (value, row, index) {
    var img = row.picPath;
    var imgUrl = "";
    if (img != null && img != '') {
        imgUrl = File_Download_Url + img;
        return [
            '<image src=' + imgUrl + ' style="width:120px;height:80px" />'
        ].join('');
    } else {
        return [
            '<image src=' + $().AbsUrlParse("/static/images/no.png") + ' style="width:120px;height:80px" />'
        ].join('');
    }
};

linkType = function (value, row, index) {
    var type = row.linkType;
    if (type == 1) {
        return [
            '<div>' + '首页广告位' + '</div>'
        ].join('')
    } else {
        return [
            '<div>' + '红包广告位'+ '</div>'
        ].join('')
    }
};

operateFormatter = function (value, row, index) {
    // if (row.picPath == null) {
    return [
        '<a class="agree" href="javascript:void(0)" >同意审核</a>' +
        '&nbsp;&nbsp;'
        // '<a class="refuse" href="javascript:void(0)" >拒绝审核</a>'
    ].join('');
    // }else {
    //     return [
    //         '<a class="replace" href="javascript:void(0)" >更换图片</a>' +
    //         '&nbsp;&nbsp;'
    //         // '<a class="refuse" href="javascript:void(0)" >拒绝审核</a>'
    //     ].join('');
    // }
};

operateEvents = {
    'click .agree': function (e, value, row) {
        showModel("addPicture-div", function () {
            $("#id").val(row.id);
        })
    },
    'click .refuse': function (e, value, row) {
        comment.showOperationTips("确定拒绝审核吗？", function () {
            $.post($().AbsUrlParse('/web/carousel/update'), {
                id: row.id
            }, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("拒绝成功");
                        var table = $("#table");
                        table.bootstrapTable("refresh");
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
            });
        });
    },
    'click .replace': function (e, value, row) {
        showModel("replace-div", function () {
            $("idUpdate").val(row.id);
            $("#image").attr("src", File_Download_Url + "/" + row.picPath);
            $("#image").attr("img-path", row.picPath);
        })
    }
};

/**
 * 修改按钮事件
 */
bindClick("button[data-event=submit-updatePicture]", function () {
    var imag = $("#picPathAdd").attr("img-path");
    if (imag == null || imag == "") {
        hint("请上传图片");
        return;
    }
    $("#picPath").val(imag);

    var form = $("#addPictureFrom");
    var param = form.formToArray();
    $.post($().AbsUrlParse('/web/carousel/addPicture'), param, function (res) {
        if (res.state && res.res.code == 40000) {
            hint('设置成功');
            //关闭model方法
            closeModel('addPicture-div');
            var table = $("#table");
            table.bootstrapTable("refresh");
        } else {
            if (res.state == false) {
                hint(res.msg);
            } else {
                hint(res.res.msg);
            }
        }
    });
});


var queryAuditingCarousel = function () {
    var busName = $("#busName").val();
    var type = $("#type").val();
    var url = $().AbsUrlParse("/web/carousel/queryAuditingCarousel?businessName=" + busName + "&type=" + type);
    var table = $("#table");
    table.bootstrapTable("refresh", {url: url});
};


/**
 * 修改按钮事件
 */
bindClick("button[data-event=submit-replacePicture]", function () {
    var imag = $("#image").attr("img-path");
    if (imag == null || imag == "") {
        hint("请上传图片");
        return;
    }
    $("#pic").val(imag);

    var form = $("#updateReplaceFrom");
    var param = form.formToArray();
    $.post($().AbsUrlParse('/web/carousel/replacePicture'), param, function (res) {
        if (res.state && res.res.code == 40000) {
            hint('设置成功');
            //关闭model方法
            closeModel('addPicture-div');
            var table = $("#table");
            table.bootstrapTable("refresh");
        } else {
            if (res.state == false) {
                hint(res.msg);
            } else {
                hint(res.res.msg);
            }
        }
    });
});